<script type="text/javascript">
function selectRow(id){
	if (id == ""){
		row = "";
	}else{
		row = $("#tblData").jqGrid("getRowData",id);
	}
	callback = "<?php echo $callback; ?>";
	if (callback != ""){
		window.opener[callback](row);
	}
	window.close();
	
}


$(function(){
	
	var numberTemplate = {formatter: 'number', align: 'right', sorttype: 'number'};
	department_id = window.opener.$("#department_id").val();

	$("#tblData").jqGrid({
		url:'index.php?r=akademik/master/tahun_ajaran/detailList',
		editUrl:'index.php?r=akMaster_TahunAjaran/edit',
		postData:{"department_id":department_id,"activeOnly":0},
		datatype: 'json',
		loadonce:true,
		mtype:"GET",
		autowidth:true,
		height:"100%",
		altRows:true,
		ignoreCase:true,
		colNames: ['id','Tahun Ajaran', 'Mulai',  'Akhir', 'Keterangan', 'Status','Action'],
		colModel: [
			{name: 'id', index: 'id', hidden:true,sorttype:'int',formatter:'int'},
			{name: 'name', index: 'name', width: 40,search:true},
			{name: 'start_date', index: 'start_date', width: 50, align: 'center', sorttype: 'date',
				formatter: 'date', formatoptions: {newformat: 'd-M-Y'}, datefmt: 'd-M-Y'},
			{name: 'end_date', index: 'end_date', width: 50, align: 'center', sorttype: 'date',
				formatter: 'date', formatoptions: {newformat: 'd-M-Y'}, datefmt: 'd-M-Y'},
			{name: 'description', index: 'description'},
			{name: 'is_active', index: 'is_active', width: 30, align: 'center', formatter: 'checkbox'},
			{name: 'act', index: 'act', width: 40, align: 'center'},
			
		],
		gridview: true,
		rownumbers: false,
		rowNum: 10,
		rowList: [5, 10, 15],
		pager: '#navTblData',
		viewrecords: true,
		caption: 'Tahun Ajaran',
		jsonReader : { 
			root:"model",
			repeatitems: false			
		},
		loadComplete:function(data){
			console.log(data);
		},
		gridComplete: function(){ 
			var ids = jQuery("#tblData").getDataIDs(); 
			for(var i=0;i<ids.length;i++){ 
				var cl = ids[i]; 
				//btnEdit = "<input style='height:22px;width:20px;' type='button' value='E' onclick=jQuery('#rowed2').editRow("+cl+"); ></ids>"; 
				//btnDelete = "<input style='height:20px;width:20px;' type='button' value='S' onclick=jQuery('#rowed2').saveRow("+cl+"); />"; 
				btnSelect = "<img title='edit' class='imgBtn' style='height:20px;width:20px;' src='images/action/Sign-Select-icon.png' onclick='selectRow(" + cl + ")' />"; 
				jQuery("#tblData").setRowData(ids[i],{act:btnSelect}) 
			} 
		},
		ondblClickRow:function(rowid,iRow,iCol,e){
			selectRow(rowid);
		}
	});
	$("#tblData").jqGrid('navGrid','#navTblData',{add:false,edit:false,search:false,del:false,refresh:false});
	
	//add search text
	$("#tblData").jqGrid('addSearchText',["nama","description"]);
});

</script>

<div>
	<table id="tblData"><tr></tr></table>
	<div id="navTblData"></div>
	<input type="button" style="width:100%" value="<?php echo Yii::t("label","Batal");?>" onClick="selectRow('')" />
	
</div>